/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistence;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import model.Operacao;

/**
 *
 * @author Cristian
 */
public class OperacaoDAO {
    private static OperacaoDAO instance = new OperacaoDAO();
    private OperacaoDAO(){
    }
    public static OperacaoDAO getInstace(){
     return instance;
    }
    
    
    public void save(Operacao op) throws SQLException, ClassNotFoundException{
        Connection conn = null;
        Statement st = null;
        ServicoDAO servicoDAO = ServicoDAO.getInstace();
        servicoDAO.save(op);
        try {
              conn = DataBaseLocator.getInsLocator().getConnection();
              st = conn.createStatement();
              st.execute("insert into operacao (idServico, descricao, dtOperacao, quarto, nomeAcompanhante )" +
                        " values ('" + op.getId() + "', '" + op.getDescricao() + "', '" + op.getDtOperacao() 
                      + "', '" + op.getQuarto() + "', '" + op.getNomeAcompanhante() + "')");
            } catch(SQLException e) {
                throw e;
            } finally {
                closeResources(conn, st);
            }
        
    }
    
    public void closeResources(Connection conn, Statement st){
      try {
            if(st!=null) st.close();
            if(conn!=null) conn.close();
          } catch(SQLException e) {
                    
          }
    }
}
